/*
 * Copyright (c) 2014. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package com.dc.gameserver.extComponents.NettyEngine3.core;


import org.jboss.netty.channel.ChannelHandler;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.handler.execution.ExecutionHandler;
import org.jboss.netty.handler.logging.LoggingHandler;


/**
 * Created with IntelliJ IDEA.
 * User: CHENLEI
 * Date: 12-10-28
 * Time: 下午7:45
 * To change this template use File | Settings | File Templates.
 * channelPipeFactory &Timer
 */
public class NServerFrameChannelPipelineFactory  implements ChannelPipelineFactory {

    private final ChannelHandler idleStateHandler;//change final
    private final ExecutionHandler executionHandler;

    private static final LoggingHandler LOGGING_HANDLER=new LoggingHandler();    // logging handle

    public NServerFrameChannelPipelineFactory(ChannelHandler idleStateHandler,ExecutionHandler executionHandler){
        this.idleStateHandler=idleStateHandler;
        this.executionHandler=executionHandler;
    }

    //mina filter chain;
    @Override
    public ChannelPipeline getPipeline() throws Exception {

         //每个sokcetChannel都会有一个解码器和编码器对应，但是编码器可以共享@Sharable
        ChannelPipeline pipeline= Channels.pipeline(this.idleStateHandler);

        pipeline.addLast("loggingHandler",LOGGING_HANDLER);
        /**解码器*****/
        pipeline.addLast("decoder", new NServerFrameDecoder(1048576,0, 2,0, 2));    // sub_reactor 数据包协议长度

        /**处理业务线程池      -----   handler***/
        pipeline.addLast("executor", this.executionHandler);  //logic_thread_worker 负责处理 业务层线程池 （数据分发 ，。。。。。。  ）

        pipeline.addLast("handler",new NServerFrameHandler());

        /**编码器*/
        pipeline.addLast("encoder", new NServerFrameEncoder());   // sub_reactor

        return pipeline;
    }

}
